package com.fulu.netty.luban.nio;

import java.nio.ByteBuffer;

/**
 * 主要展示了buffer的asReadOnlyBuffer用法
 * 它主要复制了一个只读的buffer，底层调用HeapByteBufferR
 */
public class Demo7 {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(10);
        for (int i = 0; i < buffer.capacity(); i++) {
            buffer.put((byte) i);
        }
        ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
//        readOnlyBuffer.put((byte) 1);
        readOnlyBuffer.flip();
        for (int i = 0; i < readOnlyBuffer.capacity(); i++) {
            System.out.println(readOnlyBuffer.get());
        }
    }
}
